#include "prime.h"
#include<iostream>
#include<math.h>
using namespace std;


bool checkprime (long int num)
{
    if (num <=1)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;
    else
    {
        bool prime = true;
        int divisor = 3;

        int upperLimit =sqrt(num) +1;

        while (divisor <= upperLimit)
        {
            if (num % divisor == 0)
                return false;
            divisor +=2;
        }
        return prime;
    }
}


bool rounder(long int i)
{
    long int dup1,dup2;
    int k,flag=0;
    dup1=dup2=i;
    if(checkprime(i))
    {
        do
        {   flag=0;
            k=1;
            dup1=dup2;
            while(dup1>9)
            {
                if(dup1%10==0)
                    flag=1;
                dup1/=10;
                k*=10;
            }

            dup2=((dup2%k)*10) + dup1;

            if(!checkprime(dup2))
                return false;
        } while((dup2!=i)&&(flag==0));
        if(flag==1)
            return false;
        else
            return true;
    }
    else return false;

}

bool is_circular(long int i1,long int i2){
    int n =  i1;
    int t;
    int k;

    do {
        k=1;
        t = n;
        while(t>9)
        {
            t/=10;
            k*=10;
        }
        //t=3
        n = (n-t*k)*10+t;

        if (n==i2)
            return true;
    } while((n!=i1));
    return false;

}